//
//  LoginTypeVC.swift
//  SouWeiLaiSwift
//
//  Created by yxl on 2022/4/12.
//

import UIKit
import Foundation
import Kingfisher
import SnapKit
import QMUIKit
import RxSwift
import RxCocoa


class LoginTypeVC: QMUICommonViewController {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: animated)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: animated)
    }
    
    let diposebag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
        initAction()
        initLayout()
    }
    
    // MARK: - UI
    func initUI(){
        self.view.addSubview(bjView)
        self.view.addSubview(logoView)
        self.view.addSubview(loginBtn)
        self.view.addSubview(registerBtn)
        self.view.addSubview(agreementBtn)
    }
    
    
    // MARK: - 交互
    func initAction(){
        // 登录
        loginBtn.rx.tap.subscribe(onNext: { [weak self] in
            self?.navigationController?.pushViewController(LoginVC(), animated: true)
        }).disposed(by: diposebag)
        
        // 注册
        registerBtn.rx.tap.subscribe(onNext: {
        }).disposed(by: diposebag)
        
        // 协议
        agreementBtn.rx.tap.subscribe(onNext: {
        }).disposed(by: diposebag)
    }
    
    // MARK: - Layout
    func initLayout(){
        // 背景
        bjView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        // Logo
        logoView.snp.makeConstraints { make in
            make.top.equalTo(bjView).offset(154);
            make.centerX.equalTo(bjView)
            make.width.equalTo(209)
            make.height.equalTo(70)
        }
        
        // 登陆按钮
        loginBtn.snp.makeConstraints { make in
            make.left.equalTo(bjView).offset(24)
            make.right.equalTo(bjView).offset(-24)
            make.bottom.equalTo(bjView).offset(-152)
            make.height.equalTo(48)
        }
        registerBtn.snp.makeConstraints { make in
            make.top.equalTo(loginBtn.snp_bottom)
            make.centerX.equalTo(loginBtn)
            make.width.equalTo(100)
            make.height.equalTo(48)
        }
        agreementBtn.snp.makeConstraints { make in
            make.top.equalTo(registerBtn.snp_bottom).offset(38);
            make.left.equalTo(bjView).offset(20)
            make.right.equalTo(bjView).offset(-20)
            make.centerX.equalTo(bjView);
        }
        
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        loginBtn.addCorner(conrners: .allCorners, radius: 24)
    }
    
    lazy var bjView : UIImageView = UIImageView.createBjView()
    lazy var logoView : UIImageView = UIImageView.createLogoView()
    // 登录
    lazy var loginBtn : QMUIButton = {
        let loginBtn = QMUIButton()
        loginBtn.setTitle(LanguageSet("登录"), for: .normal)
        loginBtn.titleLabel?.font = MediumFont(16)
        loginBtn.backgroundColor = HexColorA("ffffff", 0.2)!
        loginBtn.setTitleColor(BaseWhiteColor, for: .normal)
        return loginBtn
    }()
    // 注册
    lazy var registerBtn : QMUIButton = {
        let registerBtn = QMUIButton()
        registerBtn.setTitle(LanguageSet("注册"), for: .normal)
        registerBtn.titleLabel?.font = MediumFont(16)
        registerBtn.backgroundColor = BaseClearColor
        registerBtn.setTitleColor(BaseWhiteColor, for: .normal)
        return registerBtn
    }()
    // 协议
    lazy var agreementBtn : QMUIButton = {
        let agreementBtn = QMUIButton()
        agreementBtn.setTitle(LanguageSet("登录/注册 即代表你同意《索未来用户协议》"), for: .normal)
        agreementBtn.setTitleColor(BaseWhiteColor, for: .normal)
        agreementBtn.titleLabel?.font = MediumFont(12)
        agreementBtn.backgroundColor = BaseClearColor
        return agreementBtn
    }()
}

// MARK: - 懒加载
// 背景
extension UIImageView {
    static func createBjView() -> UIImageView {
        let bjView = UIImageView()
        bjView.isUserInteractionEnabled = true
        bjView.image = UIImage(named:"pic_login_bg")
        return bjView
    }
}

// Logo
extension UIImageView {
    static func createLogoView() -> UIImageView {
        let logoView = UIImageView()
        logoView.image = UIImage(named:"pic_login_logo")
        return logoView
    }
}

